package com.etc.usercenter.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.etc.common.Code;
import com.etc.common.CodeMessage;
import com.etc.usercenter.exception.TokenIsExpiredException;
import com.etc.usercenter.po.User;
import com.etc.usercenter.utils.JwtTokenUtils;

@RestController
public class AdminInfoController {

    @RequestMapping("admin/info")
    public CodeMessage admininfo(String token) throws TokenIsExpiredException {
        User u = new User();
        String token1 = token.replace(JwtTokenUtils.TOKEN_PREFIX, "");
        boolean expiration = JwtTokenUtils.isExpiration(token1);
        if (expiration) {
            throw new TokenIsExpiredException("token超时了");
        } else {
        
            u.setUsername( JwtTokenUtils.getUsername(token1));
            u.setRole(JwtTokenUtils.getUserRole(token1));
        }
        return CodeMessage.success(Code.SUCESS, "有权限",  u);
    }
}
